package com.gs.weather.controller;

import com.gs.weather.entity.DisasterSubtype;
import com.gs.weather.entity.DisasterSubtypeStrength;
import com.gs.weather.entity.DisasterType;
import com.gs.weather.service.DisasterSubtypeService;
import com.gs.weather.service.DisasterSubtypeStrengthService;
import com.gs.weather.service.DisasterTypeService;
import com.gs.weather.vo.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/9/27 0027
 */
@Controller
@RequestMapping(value = "type")
public class DisasterTypeController {
    Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    DisasterTypeService typeService;
    @Autowired
    DisasterSubtypeService subtypeService;
    @Autowired
    DisasterSubtypeStrengthService strengthService;

    //添加灾害类型
    @RequestMapping(value = "addType",method = RequestMethod.POST)
    @ResponseBody
    public Integer addType(@RequestBody DisasterType type) {
        logger.info("addType->{}",type);
        return typeService.addDisasterType(type);
    }

    //更新灾害类型
    @RequestMapping(value = "updateType",method = RequestMethod.POST)
    public ResponseEntity updateType(@RequestBody DisasterType type) {
        logger.info("updateType->{}",type);
        return typeService.updateDisasterType(type);
    }

    /*手动分页*/
    //获取灾害类型
    @RequestMapping(value = "getTypes")
    @ResponseBody
    public PageBean getType(Integer pageNum) {
        return typeService.getAllDisasterType(pageNum);
    }

    //删除灾害类型
    @RequestMapping(value = "deleteType")
    public ResponseEntity deleteType(int id) {
        return typeService.deleteDisasterType(id);
    }

    //添加灾害子类型
    @RequestMapping(value = "addSubtype",method = RequestMethod.POST)
    @ResponseBody
    public Integer addSubtype(@RequestBody DisasterSubtype subtype) {
        logger.info("addSubtype->{}",subtype);
        return subtypeService.addSubtype(subtype);
    }

    //更新灾害子类型
    @RequestMapping(value = "updateSubtype" ,method = RequestMethod.POST)
    public ResponseEntity updateSubtype(@RequestBody DisasterSubtype subtype){
        logger.info("updateSubtypeStr->{}", subtype);
        return subtypeService.updateSubtype(subtype);
    }

    //获取灾害类型的子类型
    @RequestMapping(value = "getSubtypeByTypeId")
    @ResponseBody
    public List<DisasterSubtype> getSubtypeByTypeId(int id) {
        return subtypeService.getSubtypeByTypeId(id);
    }

    //删除子类型
    @RequestMapping(value = "deleteSubtype")
    public ResponseEntity deleteSubtype(int id) {
        return subtypeService.deleteSubtype(id);
    }

    //添加灾害强度
    @RequestMapping(value = "addStrength",method = RequestMethod.POST)
    public ResponseEntity addStrength(@RequestBody DisasterSubtypeStrength subtypeStrength) {
        logger.info("addStrength->{}",subtypeStrength);
        return strengthService.addStrength(subtypeStrength);
    }

    //更新灾害强度
    @RequestMapping(value = "updateStrength",method = RequestMethod.POST)
    public ResponseEntity updateStrength(@RequestBody DisasterSubtypeStrength subtypeStrength) {
        logger.info("updateStrength->{}",subtypeStrength);
        return strengthService.updateStrength(subtypeStrength);
    }

    //删除强度
    @RequestMapping(value = "deleteStrength")
    public ResponseEntity deleteStrength(int id) {
        return strengthService.deleteStrength(id);
    }

}
